package com.turman.coroutionsample.utils

import android.util.Log
import java.io.InputStream
import java.io.OutputStream

inline fun InputStream.copyTo(outStream: OutputStream, bufferSize: Int = DEFAULT_BUFFER_SIZE,progress:(Long)->Unit):Long {
    var bytesCopied: Long = 0L
    val buffer = ByteArray(bufferSize)
    var bytes = read(buffer)
    while (bytes >= 0) {
        outStream.write(buffer,0,bytes)
        bytesCopied += bytes
        bytes = read(buffer)
//        Log.i("buobao","copy:$bytesCopied")
        progress(bytesCopied)
    }
    return bytesCopied
}